#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
@Time        : 2021/11/11 15:47
@Author      : Albert Darren
@Contact     : 2563491540@qq.com
@File        : color_model.py
@Version     : Version 1.0.0
@Description : TODO
@Created By  : PyCharm
"""
import cv2 as cv
from DIP_experiment_5.util import contrast_show
import numpy as np


def normalize(array):
    max_val, min_val = np.max(array), np.min(array)
    return (array - min_val) / (max_val - min_val)


def rgb2cmy(img):
    b, g, r = cv.split(img)
    cmy = np.zeros_like(img)  # (390, 524, 3)
    for i, v in enumerate([r, g, b]):
        cmy[:, :, i] = (1 - normalize(v)) * 255
    return cmy


PATH = "../experiment_fig/color.png"
font_path = "C:/Windows/Fonts/simhei.ttf"
im = cv.imread(PATH)
cvt_dict = {"BGR2RGB": cv.COLOR_BGR2RGB, "BGR2GRAY": cv.COLOR_BGR2GRAY, "BGR2XYZ": cv.COLOR_BGR2XYZ,
            "BGR2YCrCb": cv.COLOR_BGR2YCrCb, "BGR2HSV": cv.COLOR_BGR2HSV, "BGR2Lab": cv.COLOR_BGR2Lab}
im_dict = {}
for k, v in cvt_dict.items():
    im_dict[k] = cv.cvtColor(im, v)
im_dict["RGB2CMY"] = rgb2cmy(im)
contrast_show(im_dict, (2, 4))
